package nccloud.web.hrppl.pjapplication.pjappl.action;

import java.util.HashMap;
import java.util.Map;
import nc.itf.hrppl.pjapplication.pjappl.IPJApplHVOService;
import nc.itf.hrppl.pub.NbcrCodeTool;
import nc.itf.uif.pub.IUifService;
import nc.mddb.baseutil.MDDAOUtil;
import nc.pub.billcode.vo.BillCodeContext;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.hrppl.pjapplication.AggPjapplVO;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.ui.model.row.Cell;
import nccloud.framework.web.ui.model.row.Row;
import nccloud.framework.web.ui.pattern.extbillcard.ExtBillCard;
import nccloud.web.codeplatform.framework.action.base.BaseAction;
import nccloud.web.codeplatform.framework.action.base.RequestDTO;
import nccloud.web.codeplatform.framework.action.base.RequstParamWapper;
import nccloud.web.codeplatform.framework.action.base.ResultWapper;
import nccloud.web.codeplatform.framework.action.base.VOTransform;

public class EditPJApplHVOAction extends BaseAction {
  public Object doAction(IRequest request, RequstParamWapper paramWapper) throws Throwable {
    RequestDTO param = VOTransform.toVO(paramWapper.requestString, RequestDTO.class);
    String pk = param.getPk();
    IPJApplHVOService service = ServiceLocator.find(IPJApplHVOService.class);
    AggPjapplVO vo = service.preEditAggPjapplVO(pk);
    if (vo == null)
      return null; 
    Map<String, Object> externalData = new HashMap<>();
    String nbcrcode = NbcrCodeTool.getNbcrCodeByTranstype(vo.getParentVO().getTranstypepk());
    BillCodeContext context = service.getBillCodeContext(nbcrcode);
    externalData.put("billCodeContext", context);
    ResultWapper o = (ResultWapper)buildResult(param, true, null, new Object[] { vo });
    ExtBillCard data = (ExtBillCard)o.getData();
    //start modify by wy at 2024??7??26??
	data = TranslateActionUtil.translateAggvoVO(data,"pjapplpSub");
    Row row = data.getHead().getModel().getRows()[0];
    Cell expertgroupmember = row.getValues().get("expertgroupmember");
    if (expertgroupmember != null && expertgroupmember.getValue() != null) {
      String value = expertgroupmember.getValue().toString();
      if (value.contains(",")) {
        IUifService uifService = ServiceLocator.find(IUifService.class);
        DefdocVO[] defdocVOS = (DefdocVO[])uifService.queryByCondition(DefdocVO.class, " name in " + MDDAOUtil.getInSql(value.split(",")) + " or pk_defdoc in " + MDDAOUtil.getInSql(value.split(",")));
        if (defdocVOS != null && defdocVOS.length > 0) {
          StringBuffer sb_display = new StringBuffer();
          StringBuffer sb_value = new StringBuffer();
          for (DefdocVO defdocVO : defdocVOS) {
            sb_display.append(defdocVO.getName()).append(",");
            sb_value.append(defdocVO.getPk_defdoc()).append(",");
          } 
          expertgroupmember.setDisplay(sb_display.deleteCharAt(sb_display.length() - 1).toString());
          expertgroupmember.setValue(sb_value.deleteCharAt(sb_value.length() - 1).toString());
        } 
      } 
    } 
    return o;
  }
}
